<?php
  $link = mysql_connect('', 'admin_xbq', 'nihao')
      or die('Could not connect: ' . mysql_error());
  echo "Connected successfully\n";
  echo '<br /><br />';

  $query = "use test";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());

  //here you can't change ID.
  $sql = 'update department set d_short_name=\''.$_POST['short_name'].
  '\', d_full_name=\''.$_POST['full_name'].
  '\', d_head_name=\''.$_POST['head'].
  '\', d_head_duty=\''.$_POST['duty'].
  '\', phone=\''.$_POST['phone'].
  '\', email=\''.$_POST['email'].
  '\', depart_page=\''.$_POST['page'].
  '\' where depart_ID='.$_GET['d_id'].';';
  mysql_query($sql) or die('Query failed: ' . mysql_error());

  $sql = "select * from department where depart_ID=".$_GET['d_id'];
  $result = mysql_query($sql) or die('Query failed: ' . mysql_error());

  $line = mysql_fetch_array($result, MYSQL_ASSOC)
?>

<div  align="center">
  <form>
    <table align="center" width="500">
      <tr>
        <td class="style3">Department ID:</td>
        <td class="style3">
          <?php echo $line['depart_ID'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Department's short name:</td>
        <td  class="style3">
          <?php echo $line['d_short_name'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Department's full name:</td>
        <td  class="style3">
          <?php echo $line['d_full_name'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Head of department:</td>
        <td  class="style3">
          <?php echo $line['d_head_name'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Duty of department head:</td>
        <td  class="style3">
          <?php echo $line['d_head_duty'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Department phone:</td>
        <td  class="style3">
          <?php echo $line['phone'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Department e-mail:</td>
        <td  class="style3">
          <?php echo $line['email'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">Department homepage:</td>
        <td  class="style3">
          <?php echo $line['depart_page'];?>
        </td>
      </tr>
      <tr>
        <td class="style3">
          <a href="edit_depart.php?d_id=<?php echo $_GET['d_id'];?>">
            Edit      
          </a>
        </td>
        <td align="right" class="style3">
          <a href="show_depart.php">
            Done
          </a>
        </td>
      </tr>
    </table>
  </form>
</div>


<?php
  mysql_free_result($result);
  
  mysql_close($link);
?>
